package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.TravelInfoPoi;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ITravelInfoPoiService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行程兴趣点Controller
 *
 * @author ruoyi
 * @date 2024-09-17
 */
@Controller
@RequestMapping("/system/travel/points")
public class TravelInfoPoiController extends BaseController
{
    private String prefix = "system/travel/points";

    @Autowired
    private ITravelInfoPoiService TravelInfoPoiService;

    @RequiresPermissions("system:points:view")
    @GetMapping()
    public String points()
    {
        return prefix + "/points";
    }

    /**
     * 查询行程兴趣点列表
     */
    @RequiresPermissions("system:points:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TravelInfoPoi travelInfoPoi)
    {
        startPage();
        List<TravelInfoPoi> list = TravelInfoPoiService.selectTravelInfoPoiList(travelInfoPoi);
        return getDataTable(list);
    }

    /**
     * 导出行程兴趣点列表
     */
    @RequiresPermissions("system:points:export")
    @Log(title = "行程兴趣点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TravelInfoPoi travelInfoPoi)
    {
        List<TravelInfoPoi> list = TravelInfoPoiService.selectTravelInfoPoiList(travelInfoPoi);
        ExcelUtil<TravelInfoPoi> util = new ExcelUtil<TravelInfoPoi>(TravelInfoPoi.class);
        return util.exportExcel(list, "行程兴趣点数据");
    }

    /**
     * 新增行程兴趣点
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存行程兴趣点
     */
    @RequiresPermissions("system:points:add")
    @Log(title = "行程兴趣点", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TravelInfoPoi travelInfoPoi)
    {
        return toAjax(TravelInfoPoiService.insertTravelInfoPoi(travelInfoPoi));
    }

    /**
     * 修改行程兴趣点
     */
    @RequiresPermissions("system:points:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TravelInfoPoi travelInfoPoi = TravelInfoPoiService.selectTravelInfoPoiById(id);
        mmap.put("TravelInfoPoi", travelInfoPoi);
        return prefix + "/edit";
    }

    /**
     * 修改保存行程兴趣点
     */
    @RequiresPermissions("system:points:edit")
    @Log(title = "行程兴趣点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TravelInfoPoi travelInfoPoi)
    {
        return toAjax(TravelInfoPoiService.updateTravelInfoPoi(travelInfoPoi));
    }

    /**
     * 删除行程兴趣点
     */
    @RequiresPermissions("system:points:remove")
    @Log(title = "行程兴趣点", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(TravelInfoPoiService.deleteTravelInfoPoiByIds(ids));
    }
}
